package com.mianyang.zhangsan.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mianyang.zhangsan.common.base.BaseController;
import com.mianyang.zhangsan.common.base.R;
import com.mianyang.zhangsan.model.entity.SecVideo;
import com.mianyang.zhangsan.model.entity.SecVideoLog;
import com.mianyang.zhangsan.service.ISecVideoLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 视频观看记录
 * @author jiangjr
 * @since 2022-10-23
 */
@RestController
@RequestMapping("/video/log")
public class SecVideoLogController extends BaseController {
    @Autowired
    private ISecVideoLogService videoLogService;

    /**
     * 查询观看记录
     */
    @GetMapping
    public R searchLog(SecVideoLog videoLog,
                       @RequestParam(value = "current", defaultValue = "1") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<SecVideoLog> logs = videoLogService.selectVideoLogs(videoLog, current, pageSize);
        return success("logs", logs);
    }

    /**
     * 查询当前的视频的阅读记录
     */
    @GetMapping("/current/{fileId}")
    public R allVideo(@PathVariable("fileId") Long fileId) {
        SecVideoLog videoLog = videoLogService.selectVideoByFileId(fileId);
        return success("videoLog", videoLog);
    }

    /**
     * 删除观看记录
     */
    @DeleteMapping("/{logId}")
    public R deleteLog(@PathVariable("logId") Long logId) {
        videoLogService.removeById(logId);
        return success();
    }

    /**
     * 新增视频学习记录
     */
    @PostMapping
    public R saveVideoLog(@RequestBody SecVideoLog log) {
        videoLogService.saveVideoLog(log);
        return success();
    }

    /**
     * 修改视频观看记录
     */
    @PutMapping
    public R updateVideoLog(@RequestBody SecVideoLog log) {
        videoLogService.updateVideoLog(log);
        return success();
    }

    /**
     * 新增视频学习记录
     */
    @PostMapping("/adaptor")
    public R updateAdaptor(@RequestBody SecVideoLog log) {
        videoLogService.updateAdaptor(log);
        return success();
    }
}
